package com.woniu.aimd.controller;

import cn.dev33.satoken.util.SaResult;
import com.woniu.aimd.pojo.entity.Clazz;
import com.woniu.aimd.service.ClazzService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zcnovice
 * @data 2025/6/10 下午2:22
 */
@RestController
@RequestMapping("/clazz")
public class ClazzController {
    @Resource
    private ClazzService clazzService;

    /**
     * @Description: 测试通过
     * @return:
     * @Author:  zcnovice
     * @date:  2025/6/10 下午2:36
     */
    @PostMapping("/insert")
    public SaResult insert(@RequestBody Clazz clazz) {
        boolean result = clazzService.insert(clazz);
        if(!result)
        {
            return SaResult.error("添加失败");
        }
        return SaResult.ok("添加成功");
    }

    /**
     * @Description: 测试通过
     * @return:
     * @Author:  zcnovice
     * @date:  2025/6/10 下午2:36
     */
    @DeleteMapping("/delete")
    public SaResult delete(String classId) {
        boolean result = clazzService.delete(classId);
        if(!result)
        {
            return SaResult.error("删除失败");
        }
        return SaResult.ok("删除成功");
    }


    /**
     * @Description: 测试通过
     * @return:
     * @Author:  zcnovice
     * @date:  2025/6/10 下午2:55
     */
    @PutMapping("/update")
    public SaResult update(@RequestBody Clazz clazz) {
        boolean result = clazzService.update(clazz);
        if(!result)
        {
            return SaResult.error("更新失败");
        }
        return SaResult.ok("更新成功");
    }


    /**
     * @Description: 测试通过
     * @return:
     * @Author:  zcnovice
     * @date:  2025/6/10 下午2:58
     */
    @GetMapping("/findByClass")
    public SaResult findByClass(Clazz clazz) {
        List<Clazz> clazzes = clazzService.findByClass(clazz);
        if(clazzes == null)
        {
            return SaResult.error("查询失败");
        }
        return SaResult.data(clazzes);
    }


}
